﻿using System;
using System.Collections.Generic;
using System.Text;
using DTO;
using System.Data;
using ModuleDALCore;

namespace DAL
{
	public class CHITIETRANGDAO:DALBase
	{
		public CHITIETRANGDAO()

		{
			this.OpenConnect();
		}
		private DataTable dt;
		private string _SpName;

		public string SpName
		{
			get { return "SPCHITIETRANG"; }
			set { _SpName = value; }
		}
		public List<CHITIETRANG> GetListCTRs()
		{
			List<CHITIETRANG> ctr = new List<CHITIETRANG>();
			dt = new DataTable();

			try
			{
				dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(new CHITIETRANG(), null), ConvertClassToArray.GetValues(new CHITIETRANG(), 0));
				ctr = (List<CHITIETRANG>)ConvertDatatableToList.ConvertTo<CHITIETRANG>(dt);
			}

			catch { return null; }

			return ctr;
		}

		public DataTable GetListCTR()
		{
			dt = new DataTable();
			try
			{

				dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(new CHITIETRANG(), null), ConvertClassToArray.GetValues(new CHITIETRANG(), 0));
				return dt;
			}
			catch { return null; }
		}
		public List<CHITIETRANG> FindtheoIDLabo(CHITIETRANG bm)
		{
			dt = new DataTable();
			List<CHITIETRANG> lb = new List<CHITIETRANG>();
			try
			{
				dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(bm, null), ConvertClassToArray.GetValues(bm, 6));
				lb = (List<CHITIETRANG>) ConvertDatatableToList.ConvertTo<CHITIETRANG>(dt);
			}
			catch { return null; }
			return lb;
		}
		public String CreatenewId()
		{
			try
			{
				return "CTR" + DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(new CHITIETRANG(), null), ConvertClassToArray.GetValues(new CHITIETRANG(), 1));

			}
			catch { return null; }
		}
		public bool INSERT(CHITIETRANG ctr)
		{

			try
			{
				return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(ctr, null), ConvertClassToArray.GetValues(ctr, 2)) == 1);

			}
			catch { return false; }
		}
		public bool UPDATE(CHITIETRANG ctr)
		{

			try
			{
				return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(ctr, null), ConvertClassToArray.GetValues(ctr, 3)) == 1);

			}
			catch { return false; }
		}
		public bool DELETE(CHITIETRANG ctr)
		{

			try
			{
				return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(ctr, null), ConvertClassToArray.GetValues(ctr, 4)) == 1);

			}
			catch { return false; }
		}
	}
}